package com.zxp.server.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxp.server.mapper.MessageMapper;
import com.zxp.server.service.IMessageService;
import com.zxp.server.vo.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author fangjiale
 * @since 2021-02-08
 */
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements IMessageService {
    @Autowired
    private MessageMapper messageMapper;

    @Cacheable(value = "'Message'",key = "'List'")
    public List<Message> getMessageList() {
        return messageMapper.selectList(null);
    }

    @CacheEvict(value = "'Message'",key = "'List'")
    public boolean addMessage(Message message) {
        int i = messageMapper.insert(message);
        if (i != 1) {
            throw new RuntimeException("添加留言失败");
        }
        return true;
    }
}
